<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="退租企业" prop="park_id">
						<el-select v-model="form.park_id" placeholder="企业名称" clearable maxlength="80"></el-select>
						<!-- <sc-select v-model="form.park_id" props="{'label':'name','value':'id'}" :apiObj="$API.attractinvestment.park.getParkList" clearable filterable multiple style="width: 100%"></sc-select> -->
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="所在楼宇" prop="building_id">
						<el-input v-model="form.building_id" placeholder="所在楼宇" clearable maxlength="80"></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="所在空间" prop="space_id">
						<el-input v-model="form.space_id" placeholder="所在空间" clearable maxlength="80"></el-input>
					</el-form-item>
				</el-col>

				<el-col :lg="12">
					<el-form-item label="退租日期" prop="checkin_date">
						<el-date-picker v-model="form.build_date" type="date" value-format="YYYY-MM-DD HH:mm:ss" size="default" placeholder="提案时间"/>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="清费证明" prop="valid_date">
						<sc-upload-file :apiObj="apiObj" v-model="fileList" :data="{module:'ici_ai_space'}"
								:showFileList="false" @success="addNewFile">
					<el-button type="primary" icon="el-icon-upload">上传附件</el-button>
				</sc-upload-file>
				</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="负责人" prop="user_role">
						<select-user-dialog v-model:accountId="form.user_role" :mode="true"/>
					</el-form-item>
				</el-col>
				<el-form-item label="情况说明" prop="space_introduction">
				<sc-editor v-model="form.space_introduction" placeholder="请输入" :templates="templates" :height="400"
						   clearable style="width: 100%;"></sc-editor>
			</el-form-item>
			</el-row>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>

</template>
<script>
import selectUserDialog from "@/views/module/selectUserDialog";
import msgBoxCheckBox from "@/views/module/msgBoxCheckBox";
import AttachMenu from '@/views/module/attachMenu'
import {defineAsyncComponent} from "vue";
const scEditor = defineAsyncComponent(() => import('@/components/scEditor'));
export default {
	emits: ['success', 'closed'],
	components: {
		msgBoxCheckBox,
		selectUserDialog,
		AttachMenu,
		scEditor
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			isShowMsg:false,
			mode: "add",
			templates: [],
			fileList:[],
			userList:[],
			parkList:[],
			apiObj:this.$API.file.attach.uploadFile,
			apiUploadImg:this.$API.file.uploadImg,
			titleMap: {
				add: '退租登记',
				edit: '退租修改',
			},
			form: {
				id:'',
				dbcode:'',
				park_id: ''
			},
			rules: {
				name: [
					{required: true, message: '园区名称不能为空', trigger: 'blur'}
				]
			}
		}
	},
	mounted() {
		// this.getParkList();
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		publishDateAfter(time){
			return time.getTime()<(Date.now()-24*60*60*1000)
		},
		async getParkList(){
			let res = await this.$API.operation.park.getParkList.get();
			if (res.code == 200) {
				this.parkList = res.data.list;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res;
					if (this.mode == "add") {
						res = await this.$API.operation.checkin.insertCheckin.post(this.form);
					} else if (this.mode == "edit") {
						res = await this.$API.operation.checkin.updateCheckin.post(this.form);
					}
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		async setData(data) {
			this.form.id = data.id
			this.form.dbcode = data.dbcode
			this.form.space_id = data.space_id
			this.form.park_id = data.park_id
			this.form.building_id = data.building_id
			this.form.enterprise_id = data.enterprise_id
			this.form.checkin_date = data.checkin_date
			this.form.valid_date = data.valid_date
			this.form.checkin_status = data.checkin_status
			this.form.checkout_date = data.checkout_date
			this.form.update_time = data.update_time
		},
		addNewFile(res, file)
        {
            let tArr=[];
            if(this.form.attach_upload!=undefined&&this.form.attach_upload!=null&&this.form.attach_upload!=''){
                tArr= this.form.attach_upload.split(",");
            }
            tArr.push(res.data.attachId);
            this.form.attach_upload = tArr.join(",");
        }
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
